import { http } from "../utils/http"
import { routeCombine } from "../utils/tool"

export async function getOpen(room: string, user: string) {
    const base = "open"
    return await http.get<string>(routeCombine(base, room, user))
}

export async function getJoin(room: string, user: string) {
    const base = 'join'
    return await http.get<string>(routeCombine(base, room, user))
}
export interface RoomItem {
    name?: string
    owner?: string;
    state?: number; //0为不可进入 1可进入 2为已满 3为游戏进行中 4为游戏已结束
    count?: number; //游戏人数 max:2
}
export async function getRoom() {
    const base = 'room'
    return await http.get<RoomItem[]>(routeCombine(base))
}
export interface DropData {
    user: string
    color?:string
    xPoint: number
    yPoint: number
}
export interface CheckResponse {
    state: string
    data: any
}
export async function getCheck(room: string, user: string) {
    const base = 'check'
    return await http.get<CheckResponse>(routeCombine(base, room, user))
}

export async function getReady(room: string, user: string) {
    const base = 'ready'
    return await http.get<string>(routeCombine(base, room, user))
}

export async function postDrop(room: string, data: DropData) {
    const base = 'drop'
    return await http.post<string>(routeCombine(base, room), data)
}

export interface SelectData {
    user: string
    color: string
}
export async function postSelect(room: string, data: SelectData) {
    const base = 'select'
    return await http.post<string>(routeCombine(base, room), data)
}       

export async function getExit(room: string,user: string) {
    const base = 'exit'
    return await http.get<string>(routeCombine(base, room,user))
}
export async function getHistory(room: string,user: string) {
    const base = 'history'
    return await http.get<DropData[]>(routeCombine(base, room,user))
}
